package com.xhj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xhj.config.TeacherQuery;
import com.xhj.entity.Teacher;
import com.xhj.mapper.TeacherMapper;
import com.xhj.service.TeacherService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {

    @Autowired
    private TeacherMapper teacherMapper;

    @Override
    public IPage<Teacher> pageList(Page<Teacher> pageParam, TeacherQuery teacherQuery) {
        if (teacherQuery == null) {
            return teacherMapper.selectPage(pageParam,null);
        }
        QueryWrapper<Teacher> queryWrapper = new QueryWrapper<>();
        // 获取teacherQuery的属性值
        String name = teacherQuery.getName();
        Integer level = teacherQuery.getLevel();
        String begin = teacherQuery.getBegin();
        String end = teacherQuery.getEnd();

        if (!StringUtils.isEmpty(name)) queryWrapper.like("name",name);

        if (level != null) queryWrapper.eq("level",level);

        if (!StringUtils.isEmpty(begin)) queryWrapper.ge("gmt_create",begin);

        if (!StringUtils.isEmpty(end)) queryWrapper.le("gmt_create",end);

        return teacherMapper.selectPage(pageParam,queryWrapper);
    }
}
